/// 社区评论数据模型
/// 记录用户对社区帖子的评论
class CommunityCommentEssence {
  final String id;
  final String communityId;
  final String userId;
  final String content;
  final DateTime createTime;

  CommunityCommentEssence({
    required this.id,
    required this.communityId,
    required this.userId,
    required this.content,
    required this.createTime,
  });

  /// 从Map创建CommunityCommentEssence
  factory CommunityCommentEssence.fromMap(Map<String, dynamic> map) {
    return CommunityCommentEssence(
      id: map['id'] as String,
      communityId: map['communityId'] as String,
      userId: map['userId'] as String,
      content: map['content'] as String,
      createTime: DateTime.parse(map['createTime'] as String),
    );
  }

  /// 转换为Map
  Map<String, dynamic> toMap() {
    return {
      'id': id,
      'communityId': communityId,
      'userId': userId,
      'content': content,
      'createTime': createTime.toIso8601String(),
    };
  }

  /// 复制并修改部分属性
  CommunityCommentEssence copyWith({
    String? id,
    String? communityId,
    String? userId,
    String? content,
    DateTime? createTime,
  }) {
    return CommunityCommentEssence(
      id: id ?? this.id,
      communityId: communityId ?? this.communityId,
      userId: userId ?? this.userId,
      content: content ?? this.content,
      createTime: createTime ?? this.createTime,
    );
  }
}
